NPM Module
NPM Module
Install
1
npm i @botbye/client
or
1
yarn add @botbye/client
Configuration
Call initChallenges with your project client-key:
1
2
3
4
5
6
import { initChallenges } from "@botbye/client";
const runChallenge = await initChallenges({
// Use your client-key
clientKey: "00000000-0000-0000-0000-000000000000"
});
Usage
Generate token using runChallenge and send this token in any convenient way to the backend. For example in x-botbye-token header:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { runChallenge } from "@botbye/client";
const botByeToken = await runChallenge();
fetch(
'https://domain.com',
{
method: "POST",
headers: {
// "x-botbye-token" is an example — send this token in any convenient way.
"x-botbye-token": botByeToken
}
}
)
Challenge runner
Package also exports runChallenge function. Before call it, make sure that initChallenges was called earlier.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { initChallenges, runChallenge } from "@botbye/client";
initChallenges({
// Use your client-key
clientKey: "00000000-0000-0000-0000-000000000000"
});
...
const botByeToken = await runChallenge()
fetch(
'https://domain.com',
{
method: "POST",
headers: {
"x-botbye-token": botByeToken
}
}
)
User identification
Call setUserId after a successful authentication to associate the current session with a user. This helps BotBye detect multi-account abuse.
1
2
3
4
5
6
7
import { setUserId } from "@botbye/client";
const response = await login({ username, password });
if (response.userId) {
setUserId(response.userId);
}